const { ordersModel } = require("./models/ordersModel");
// 获取订单数据
module.exports.getOrders = async function ({ currentPage, pageSize, value = "name", input = "", state }) {
    const total = (await ordersModel
        .find({
            state: { $regex: state + '', $options: '$i' }
        })
        .find({
            [value]: { $regex: input, $options: '$i' }
        })).length//获取搜索回来据总条数
    // 模糊搜索
    const result = await ordersModel
        .find({
            state: { $regex: state + '', $options: '$i' }
        })
        .find({
            [value]: { $regex: input, $options: '$i' }
        })
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize)//当前页数

    return {
        total, result
    }
}

// 获取不同状态的订单
module.exports.getOtherOrders = async function (num) {
    const data = await ordersModel.find(num);
    return data
}

// 新增订单
module.exports.addOrders = async function (newOrders) {
    //  新增数据
    const data = await ordersModel.create(newOrders);
    return data
}

// 删除订单
module.exports.deleteOrders = async function (_id) {
    console.log(_id, 33333);
    return await ordersModel.deleteOne(_id);
}

// 查看详情
module.exports.getDetails = async function (_id) {

    return await ordersModel.findById(_id);
}

